package com.example.juyuanapp.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.juyuanapp.R;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
    Button btnLogin;
    EditText etName,etPassword;
    TextView tvRegist;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
    }


    private void initView() {
        btnLogin = findViewById(R.id.btn_login);
        btnLogin.setOnClickListener(this);
        tvRegist = findViewById(R.id.tv_regist);
        tvRegist.setOnClickListener(this);

        etName = findViewById(R.id.et_login_name);
        etPassword = findViewById(R.id.et_login_password);
    }

    @Override
    public void onClick(View v) {
        String name = etName.getText().toString();
        String password = etPassword.getText().toString();
        switch (v.getId()){
            case R.id.btn_login:
                //网络访问得到用户信息并核对
                if (!name.equals("")&&!password.equals("")){
                    Intent intent1 = new Intent(this,FoodListActivity.class);
                    startActivity(intent1);
                }else {
                    Toast.makeText(this, "用户名和密码不能为空！", Toast.LENGTH_SHORT).show();
                }

                break;
            case R.id.tv_regist:
                Intent intent2 = new Intent(this,RegistActivity.class);
                startActivity(intent2);
                break;
        }
    }
}